package com.jack.webrtcsimple

import android.Manifest
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import pub.devrel.easypermissions.EasyPermissions

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        val roomEditText: EditText = findViewById(R.id.RoomEditText)
        findViewById<Button>(R.id.setRoomBtn).setOnClickListener(object : View.OnClickListener {
            override fun onClick(view: View?) {
                val roomId = roomEditText.getText().toString()
                if ("" != roomId) {
                    val intent: Intent = Intent(this@MainActivity, CallActivity::class.java)
                    intent.putExtra("roomId", roomId)
                    startActivity(intent)
                }
            }
        })

        val perms = arrayOf(
            Manifest.permission.CAMERA,
            Manifest.permission.RECORD_AUDIO
        )
        if (!EasyPermissions.hasPermissions(this, *perms)) {
            EasyPermissions.requestPermissions(
                this,
                "Need permissions for camera & microphone",
                0,
                *perms
            )
        }
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<String?>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this)
    }

}